<template>
	<view class="uni-common-mt">
		<!-- 酒店信息  -->
		<view class="hotel-info-card uni-common-mt" v-if="hotel != null">
			<!-- 名称 -->
			<view class="hotel-info-card__title">
				<text class="font-bold">{{ hotel.hotelName }}</text>
				<!-- <buk-tag bgColor="#242424" is-flex text-color="#FADEAB"
					class="margin-left-xs">特色</buk-tag> -->
			</view>
			<!-- 评分 -->
			<view class="flex justify-between margin-bottom margin-top-xs">
				<buk-rate-capsule text="真棒👍🏻" :rate="` ` + hotel.rstar" />
			</view>

		</view>

		<!-- 时间 -->
		<view class="user-choose-time flex align-center justify-center">
			<view class="flex align-center">
				<text class="font32 font-normal">{{ hotelStore.checkInDate }}</text>
				<text class="font24 margin-left-xs">入住</text>
			</view>
			<buk-time-capsule class="margin-lr" :text="hotelStore.nights + ` 晚`" :line="false" color="#ffffff"
				textColor="#ffffff"></buk-time-capsule>
			<view class="flex align-center">
				<text class="font32 font-normal">{{ hotelStore.checkOutDate }}</text>
				<text class="font24 margin-left-xs">离店</text>
			</view>
		</view>

		<view class="hotel-room-type">
			<buk-room-type-card :hotelId="hotel.id" :days="hotelStore.nights" v-for="(item, index) in hotel.roomTypes" :data="item" v-if="hotel.roomTypes"
				:key="index"></buk-room-type-card>
		</view>

	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from 'vue'
	import {
		onShow,
		onLoad
	} from '@dcloudio/uni-app'
	import {
		useHotelStore
	} from '@/store/hotel.js'

	const hotelStore = useHotelStore()

	let hotel = ref(null)

	onLoad(() => {
		// console.log('on load')
		if (hotelStore.cityId == 0) {
			uni.redirectTo({
				url: "/pages/hotel/HotelList"
			})
			return
		}
		
		try {
			hotel.value = hotelStore.hotelInfo
			// console.log(hotel)
			// console.log(hotel.value)
		} catch (err) {
			console.log(err)
		}
	})

	function generateOrder(hotelId, roomTypeId, roomId, price, ratePlan) {
		try {
			let orderInfo = {
				hotelId,
				roomTypeId,
				roomId,
				price,
				'checkInDate': hotelStore.checkInDate,
				'checkOutDate': hotelStore.checkOutDate,
				'roomCount': hotelStore.roomCount
			}

			hotelStore.updateOrderInfo(orderInfo)
			hotelStore.updateRatePlan(ratePlan)

			uni.navigateTo({
				url: '/pages/hotel/OrderGenerate'
			});
		} catch (err) {
			console.log(err)
		}

	}
</script>

<style lang="scss">
	.uni-list-item__extra {
		// width: 25%;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: flex-end;
		align-items: center;
	}


	.uni-list-item__extra-text {
		color: $uni-text-color-grey;
		font-size: $uni-font-size-sm;
	}

	.uni-list-item__content {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		padding-right: 8px;
		flex: 1;
		color: #3b4144;
		// overflow: hidden;
		flex-direction: column;
		justify-content: space-between;
		overflow: hidden;
	}

	.uni-list-item__content-title {
		font-size: $uni-font-size-base;
		color: #3b4144;
		overflow: hidden;
	}

	.hotel-banner {
		height: 580rpx;
	}

	.hotel-info-card {
		position: relative;
		top: -60rpx;
		padding: 32rpx;
		// height: 488rpx;
		background: #ffffff;
		border-radius: 50rpx 50rpx 20rpx 20rpx;
		margin-bottom: -60rpx;

		&__tags {
			white-space: nowrap;
			width: 500rpx;
			overflow: hidden;
		}

		&__title {
			font-size: 36rpx;
			font-weight: 400;
			line-height: 50rpx;
			color: #242424;
			display: flex;
			flex-wrap: wrap;
			align-items: center;
		}

		&__map {
			padding: 24rpx;
			background: #f8f8f8;
			border-radius: 20rpx 20rpx 20rpx 20rpx;

			&__title {
				width: 466rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #242424;
				line-height: 39rpx;
			}
		}
	}

	.indicator-num {
		padding: 2px 0;
		background-color: rgba(0, 0, 0, 0.35);
		border-radius: 100px;
		width: 35px;
		justify-content: center;

		&__text {
			color: #ffffff;
			font-size: 12px;
		}
	}

	.user-choose-time {
		margin: 24rpx 0;
		padding: 12rpx 32rpx;
		// background: #242424;
		color: #ffffff;
	}

	.hotel-room-type {
		padding: 0 16rpx;
		display: flex;
		flex-direction: column;
	}
</style>